<?php
	class UserManageAction extends Action{
		//用户管理首页
		public function index(){
			$this->display();
		}
		//添加管理员页面
		public function addAdmin(){
			$this->display();
		}
		//添加管理员
		public function do_addAdmin(){
			$term=$this->_post('r1');					//获取管理员标识符 0为管理员 1为文章编辑者
			$data['UserName']=$this->_post('email');	//获取用户名
			$data['TrueName']=$this->_post('truename');	//获取真实名字
			$data['Password']=md5($this->_post('password'));	//获取密码
			$data['Phone']=$this->_post('phone');		//获取手机号
			$data['Email']=$this->_post('email1');		//获取邮箱
			$user=M('users');							//实例化用户表
			if($term==0){								//标识符为0执行
				$data['UserType']=6;					//设置用户类型为6  6是管理员
			}
			if($term==1){								//标识符为1执行
				$data['UserType']=7;					//设置用户标识符为7  7是文章编辑者
			}
			//添加数据库
			if($user->add($data)){
				$this->success_ajax('添加成功');
			}else{
				$this->error_ajax('添加失败');
			}
		}
		//教师管理页面
		public function teacher(){
			$where="";
			$keyword1=$this->_post('keyword1');  //获取第一个输入框内容
			$keyword2=$this->_post('keyword2');	//获取第二个输入框内容
			$term1=$this->_post('term1');		//获取第一个下拉框值
			$term2=$this->_post('term2');		//获取第二个下拉框值
			//获取分页条件
			$truename=$this->_post('truename');	
			$username=$this->_post('username');
			$email=$this->_post('email');
			$phone=$this->_post('phone');

			if(!empty($term2)){					//如果第二个下拉框值不为空
				$team=M('team');				//实例化团队表
				$teaminstructors=M('teaminstructors');	//实例化团队和教官关联表
				$tarr=$team->where('status = '.$term2)->field('Id')->select();	//获取符合条件的团队id
				$tn=count($tarr);						//获取团队数量
				for($i=0;$i<$tn;$i++){
					$tiarr[]=$tarr[$i]['Id'];			//组合成一维数组
				}	
				$map['TeamId']=array('in',$tiarr);		//组合查询条件
				$tiarrid=$teaminstructors->where($map)->field('InstructorId')->select();	//获取教官或教师id数组
				$tm=count($tiarrid);					//获取教官或教师数量
				for($j=0;$j<$tm;$j++){		
					$tid[]=$tiarrid[$j]['InstructorId'];	//组合成一维数组
				}
				$uarr=array_unique($tid);					//去掉重复的值
				$ustr=implode($uarr,',');					//组合成字符串
				$where='u.UserId in ('.$ustr.') and ';		//组合查询条件
				$this->assign('term2',$term2);
			}
			if($term1 == "SchoolId"){						//如果第一个下拉框值等于SchoolId
				$high=M('highschool');						//实例化学校表
				$harr=$high->where('SchoolName = '."'".$keyword1."'")->field('Id')->find();	//获取学校名称
				$where.='u.SchoolId = '.$harr['Id'].' and ';					//组合查询语句
				$this->assign('term1',$term1);
				$this->assign('keyword1',$keyword1);
			}
			if($term1 == "IndustryId"){						//如果第一个下拉框值等于IndustryId
				$enterprise=M('enterprise ');				//实例化公司表
				$teacher=M('teacher');						//实例化详情表
				$iarr=$enterprise->where('Name = '."'".$keyword1."'")->field('Id')->find();		//获取公司id
				$teaarr=$teacher->where('EnterpriseId='.$iarr['Id'])->field('UserId')->select();	//获取教师或教官id
				$teanum=count($teaarr);						//获取教师教官数量
				for($i=0;$i<$teanum;$i++){
					$teaarrid[]=$teaarr[$i]['UserId'];		//组合成一维数组
				}
				$teastr=implode($teaarrid,',');				//组合成字符串
				$where.='u.UserId in '.'('.$teastr.') and ';	//组合查询语句
				$this->assign('term1',$term1);
				$this->assign('keyword1',$keyword1);
			}
			if(!empty($keyword2)){
				$where.='u.TrueName = '."'".$keyword2."' and ";		//组合查询语句
				$this->assign('truename',$keyword2);
			}
			if(!empty($truename)){
				$where.='u.TrueName = '."'".$truename."' and ";		//组合查询语句
				$this->assign('truename',$truename);
			}
			if($term1 == "UserName"){
				$where.='u.UserName like '."'%".$keyword1."%' and ";	//组合查询语句
				$this->assign('username',$keyword1);
			}
			if(!empty($username)){
				$where.='u.UserName like '."'%".$username."%' and ";	//组合查询语句
				$this->assign('username',$username);
			}
			if($term1 == 'Email'){
				$where.='u.Email like '."'%".$keyword1."%' and ";		//组合查询语句
				$this->assign('email',$keyword1);
			}
			if(!empty($email)){
				$where.='u.Email like '."'%".$email."%' and ";		//组合查询语句
				$this->assign('email',$email);
			}
			if($term1 == 'PhoneNumber'){
				$where.='u.PhoneNumber like '."'%".$keyword1."%' and ";	//组合查询语句
				$this->assign('phone',$keyword1);
			}
			if(!empty($phone)){
				$where.='u.PhoneNumber like '."'%".$phone."%' and ";	//组合查询语句
				$this->assign('phone',$phone);
			}
			if($_POST['numPerPage']){
				$pagesize = $_POST['numPerPage'];
				$_GET['page'] = $_POST['pageNum'];//自定义翻页类需要 GET （当前页）信息
			}else{
				$pagesize=20;
			}	
			$user=M('users');			//实例化用户表
			$model = M();
			$list = $model->table('users u,highschool h')->field('u.IsApproved,u.IsJury,u.UserId,u.UserName,h.SchoolName,u.UserType,u.TrueName,u.PhoneNumber,u.Email,u.CreateDate')->where($where.'u.UserType = 3 and u.SchoolId=h.Id')->select();    //获取教师信息
			$array = $model->table('users u,teacher t,enterprise e')->field('u.IsApproved,u.IsJury,u.UserId,u.UserName,u.SchoolId,u.UserType,u.TrueName,u.PhoneNumber,u.Email,u.CreateDate,e.Name')->where($where.'u.UserType = 4 and u.UserId=t.UserId and t.EnterpriseId=e.Id')->select();	//获取教官信息
			if(empty($list)){
				$list=array();		//如果教师为空，定义为空数组
			}
			if(empty($array)){
				$array=array();		//如果教官为空，定义为空数组
			}
			$allarr = array_merge($list,$array);	//合并教师和教官
			//排序数组
			foreach($allarr as $key=>$val){
				$time[$key]=$val['CreateDate'];
			}
			array_multisort($time,$allarr);     
			$arr1 = array_reverse($allarr);

			$num = count($arr1);  	//获取最后查询数量
			$nu=$pagesize;			//获取当前页数	
			$totalpage=ceil($num/$nu);	//获取总页数
			if(empty($page)){
				$page=intval($_GET["page"]);
			}
			if($page<1){
				$page=1;
			}
			if($page>$totalpage){
				$page=$totalpage;
			}
			$offset=($page-1)*$nu;  //获取偏移量
			$arr = array_slice($arr1,$offset,$nu);	//截取数组
			$this->assign('currentPage',$page); //分配当前页数
			$this->assign('pagesize',$nu); //分配一页显示的条数
			$this->assign('totalCount',$num);
			$titles=array('用户Id','用户名','所在单位','用户类型','真实姓名','联系电话','邮箱','注册时间','操作');	
			$this->assign('titles',$titles);
			$this->assign('arr',$arr);
		/*	$excel=$this->_get('excel');
			if($excel==1){
				import('ORG.Net.PHPExcel');
				//实例化新工作薄对象 实例化新工作薄对象
				$excel = new PHPExcel();
				$sheet=$excel->getActiveSheet();
				for($i=0;$i<$num;$i++){
					$arr[$i]['Time']=date('Y-m-d H:i:s',$arr[$i]['CreateDate']);
					if($arr[$i]['UserType']==3){
						$arr[$i]['User']='教师';
						$arr[$i]['School']=$arr[$i]['SchoolName'];
					}elseif($arr[$i]['UserType']==4){
						$arr[$i]['User']='教官';
						$arr[$i]['School']=$arr[$i]['Name'];
					}
					for($j=0;$j<count($arr[$i]-3);$j++){
						$sheet->getCell('A'.$j)->setValue($arr[$i]['UserId']);	
						$sheet->getCell('B'.$j)->setValue($arr[$i]['UserName']);
						$sheet->getCell('C'.$j)->setValue($arr[$i]['School']);
						$sheet->getCell('D'.$j)->setValue($arr[$i]['UserId']);
						$sheet->getCell('E'.$j)->setValue($arr[$i]['TrueName']);
						$sheet->getCell('F'.$j)->setValue($arr[$i]['PhoneNumber']);
						$sheet->getCell('G'.$j)->setValue($arr[$i]['Email']);
						$sheet->getCell('H'.$j)->setValue($arr[$i]['Time']);
					}
				}
				
				//临时文件
				$file=$file="C:/Windows".uniqid().'.xls';
				echo 1;
				$write=PHPExcel_IOFactory::createWriter($excel,'Excel5');
				$write->save($file);
			}*/
			$this->display();
		}
		//删除用户
		public function delete(){
			$id=$this->_get('uid');						//获取用户id
			$user=M('users');							//实例化用户表
			$teacher=M('teacher');						//实例化教师和企业教官详情表
			$list=$teacher->field('UserId')->select();	//获取教师和企业教官的id
			foreach($list as $v){
				if(in_array($id,$v)){
					$teacher->where(array('UserId'=>$id))->delete();		//如果教师填写了详情删除
				}
				break;
			}
			if($user->where('UserId ='.$id)->delete()){
				$this->success_ajax('删除成功');			//删除用户信息，返回成功
			}else{
				$this->error_ajax('删除失败');				//删除用户信息，返回失败
			}
		}
		//把用户审核通过
		public function pass(){	
			$id = $this->_get('uid');					//获取用户id
			$user = M('users');					//实例化用户表
			
			$data['IsApproved']=1;				//用户通过
			$arr=$user->where('UserId = '.$id)->field('UserId,TrueName')->find();
			if($user->where('UserId='.$id)->save($data)){	
				$this->success_ajax('操作成功');		//通过，返回成功		
			}else{
				$this->error_ajax('操作失败');			//未通过，返回失败
			}
		} 
		//把用户设置成评委
		public function jury(){
			$id = $this->_get('uid');			//获取用户id
			$user = M('users');			//实例化用户表
			$jury = M('jury');
			$data['IsJury']=1;			//设为评委
			$arr=$user->where('UserId = '.$id)->field('UserId,TrueName')->find();
			if($user->where('UserId='.$id)->save($data) && $jury->add($arr)){
				$this->success_ajax('操作成功');			//设置成功，返回成功
			}else{
				$this->error_ajax('操作失败');				//设置失败，返回失败
			}
		}
		//查看用户信息
		public function info(){
			$id = $this->_get('uid');   		//获取用户信息
			$user = M('users');			//实例化用户表
			$teacher = M('teacher');	//实例化教师教官信息表
			$school = M('highschool');
			$iarr=array();
			$earr=array();
			$list = $user->field('UserId,UserName,TrueName,SchoolId,UserType,PhoneNumber,Email,CreateDate')->where('UserId='.$id)->find();	//获取用户基础信息
			$arr = $teacher->field('EduLevel,DepartmentName,IndustryId,Job,Title,Address,PostalCode,OtherPhone,FixedPhone,QQ,Fetion,IdCard,PersonalIntroduce,Age,EnterpriseId')->where('UserId='.$id)->find();				//获取用户详细信息
			if(empty($arr)){
				$arr=array();
			}else{
				$industry=M('industry');				//实例化行业表
				$enterprise=M('enterprise');			//实例化公司表
				$iarr=$industry->where('Id ='.$arr['IndustryId'])->field('Name')->find();		//查询行业名
				$earr=$enterprise->where('Id ='.$arr['EnterpriseId'])->field('Name eName')->find();	//查询公司名
				if(empty($earr)){
					$earr=array();
				}
				if(empty($iarr)){
					$iarr=array();
				}
			}
			$array['SchoolName']="";
			$array['eName']="";
			$sarr=$school->where('Id = '.$list['SchoolId'])->field('SchoolName')->find();	//查询学校名
			if(empty($sarr)){
				$sarr=array();
			}
			$arrall=array_unique(array_merge($array,$list,$arr,$sarr,$iarr,$earr));		//组合用户信息
		//	dump($arrall);
			$this->assign('list',$arrall);
			$this->display();	
		}
		//未通过审核的用户
		public function unpass(){
		$where="";
			$keyword1=$this->_post('keyword1');  //获取第一个输入框内容
			$keyword2=$this->_post('keyword2');	//获取第二个输入框内容
			$term1=$this->_post('term1');		//获取第一个下拉框值
			$term2=$this->_post('term2');		//获取第二个下拉框值
			//获取分页条件
			$truename=$this->_post('truename');	
			$username=$this->_post('username');
			$email=$this->_post('email');
			$phone=$this->_post('phone');

			if(!empty($term2)){					//如果第二个下拉框值不为空
				$team=M('team');				//实例化团队表
				$teaminstructors=M('teaminstructors');	//实例化团队和教官关联表
				$tarr=$team->where('status = '.$term2)->field('Id')->select();	//获取符合条件的团队id
				$tn=count($tarr);						//获取团队数量
				for($i=0;$i<$tn;$i++){
					$tiarr[]=$tarr[$i]['Id'];			//组合成一维数组
				}	
				$map['TeamId']=array('in',$tiarr);		//组合查询条件
				$tiarrid=$teaminstructors->where($map)->field('InstructorId')->select();	//获取教官或教师id数组
				$tm=count($tiarrid);					//获取教官或教师数量
				for($j=0;$j<$tm;$j++){		
					$tid[]=$tiarrid[$j]['InstructorId'];	//组合成一维数组
				}
				$uarr=array_unique($tid);					//去掉重复的值
				$ustr=implode($uarr,',');					//组合成字符串
				$where='u.UserId in ('.$ustr.') and ';		//组合查询条件
				$this->assign('term2',$term2);
			}
			if($term1 == "SchoolId"){						//如果第一个下拉框值等于SchoolId
				$high=M('highschool');						//实例化学校表
				$harr=$high->where('SchoolName = '."'".$keyword1."'")->field('Id')->find();	//获取学校名称
				$where.='u.SchoolId = '.$harr['Id'].' and ';					//组合查询语句
				$this->assign('term1',$term1);
				$this->assign('keyword1',$keyword1);
			}
			if($term1 == "IndustryId"){						//如果第一个下拉框值等于IndustryId
				$enterprise=M('enterprise ');				//实例化公司表
				$teacher=M('teacher');						//实例化详情表
				$iarr=$enterprise->where('Name = '."'".$keyword1."'")->field('Id')->find();		//获取公司id
				$teaarr=$teacher->where('EnterpriseId='.$iarr['Id'])->field('UserId')->select();	//获取教师或教官id
				$teanum=count($teaarr);						//获取教师教官数量
				for($i=0;$i<$teanum;$i++){
					$teaarrid[]=$teaarr[$i]['UserId'];		//组合成一维数组
				}
				$teastr=implode($teaarrid,',');				//组合成字符串
				$where.='u.UserId in '.'('.$teastr.') and ';	//组合查询语句
				$this->assign('term1',$term1);
				$this->assign('keyword1',$keyword1);
			}
			if(!empty($keyword2)){
				$where.='u.TrueName = '."'".$keyword2."' and ";		//组合查询语句
				$this->assign('truename',$keyword2);
			}
			if(!empty($truename)){
				$where.='u.TrueName = '."'".$truename."' and ";		//组合查询语句
				$this->assign('truename',$truename);
			}
			if($term1 == "UserName"){
				$where.='u.UserName like '."'%".$keyword1."%' and ";	//组合查询语句
				$this->assign('username',$keyword1);
			}
			if(!empty($username)){
				$where.='u.UserName like '."'%".$username."%' and ";	//组合查询语句
				$this->assign('username',$username);
			}
			if($term1 == 'Email'){
				$where.='u.Email like '."'%".$keyword1."%' and ";		//组合查询语句
				$this->assign('email',$keyword1);
			}
			if(!empty($email)){
				$where.='u.Email like '."'%".$email."%' and ";		//组合查询语句
				$this->assign('email',$email);
			}
			if($term1 == 'PhoneNumber'){
				$where.='u.PhoneNumber like '."'%".$keyword1."%' and ";	//组合查询语句
				$this->assign('phone',$keyword1);
			}
			if(!empty($phone)){
				$where.='u.PhoneNumber like '."'%".$phone."%' and ";	//组合查询语句
				$this->assign('phone',$phone);
			}
			if($_POST['numPerPage']){
				$pagesize = $_POST['numPerPage'];
				$_GET['page'] = $_POST['pageNum'];//自定义翻页类需要 GET （当前页）信息
			}else{
				$pagesize=20;
			}	
			$user=M('users');			//实例化用户表
			$model = M();
			$list = $model->table('users u,highschool h')->field('u.IsApproved,u.IsJury,u.UserId,u.UserName,h.SchoolName,u.UserType,u.TrueName,u.PhoneNumber,u.Email,u.CreateDate')->where($where.'u.UserType = 3 and u.SchoolId=h.Id and IsApproved = 0')->select();    //获取教师信息
			$array = $model->table('users u,teacher t,enterprise e')->field('u.IsApproved,u.IsJury,u.UserId,u.UserName,u.SchoolId,u.UserType,u.TrueName,u.PhoneNumber,u.Email,u.CreateDate,e.Name')->where($where.'u.UserType = 4 and u.UserId=t.UserId and t.EnterpriseId=e.Id and IsApproved = 0')->select();	//获取教官信息
			if(empty($list)){
				$list=array();		//如果教师为空，定义为空数组
			}
			if(empty($array)){
				$array=array();		//如果教官为空，定义为空数组
			}
			$allarr = array_merge($list,$array);	//合并教师和教官
			//排序数组
			foreach($allarr as $key=>$val){
				$time[$key]=$val['CreateDate'];
			}
			array_multisort($time,$allarr);     
			$arr1 = array_reverse($allarr);

			$num = count($arr1);  	//获取最后查询数量
			$nu=$pagesize;			//获取当前页数	
			$totalpage=ceil($num/$nu);	//获取总页数
			if(empty($page)){
				$page=intval($_GET["page"]);
			}
			if($page<1){
				$page=1;
			}
			if($page>$totalpage){
				$page=$totalpage;
			}
			$offset=($page-1)*$nu;  //获取偏移量
			$arr = array_slice($arr1,$offset,$nu);	//截取数组
			$this->assign('currentPage',$page); //分配当前页数
			$this->assign('pagesize',$nu); //分配一页显示的条数
			$this->assign('totalCount',$num);	
			$this->assign('arr',$arr);
			$this->display();
		}
		//重置密码
		Public function resetPass(){
			//获取被找回密码的账号信息
			$data['Email']= $this->_get('Email');
			$data['UserId']=$this->_get('UserId');
			$user=M('users');
			$arr=$user->where($data)->field('UserName')->find();
			if(empty($arr)){
				$this->error_ajax('信息错误，您不能修改密码');
				break;
			}
			$pwd=rand(100000,999999);
			//定义一个发送邮件的内容
			$message=<<<str
你好！{$arr['UserName']}
<h2>欢迎使用本网站</h2>
您现在的密码为:<br/><br/>
{$pwd}<br /><br />
www.***.com
str;
			//发送激活账号邮件
			$b = $this->sendMail($data['Email'],"密码找回",$message);
			$list['Password'] = md5($pwd);
			$up=$user->where($data)->save($list);
			if($b and $up){
				$this->success_ajax('重置密码成功');
			}else{
				$this->error_ajax("重置密码失败");
			}
		}
		private function sendMail($address,$title,$message){
			require("./Match/Tpl/Include/PHPMailer/class.phpmailer.php");//导入mail类文件
			//创建mail对象
			$mail = new PHPMailer();
			$mail->IsSMTP(); //设置使用SMTP服务器发送
			$mail->Host = C('MAIL_HOST');  //设置126邮箱服务 
			$mail->SMTPAuth = true;     // 设置需要验证
			$mail->Username = C('MAIL_USER');  // 发件人使用邮箱
			$mail->Password = C('MAIL_PWD'); // 设置发件人密码
			$mail->From = C('MAIL_FORM');// 发件人邮箱
			$mail->FromName = C('MAIL_NAME'); //发送者名称
			$mail->AddAddress($address); // 添加发送地址
			$mail->IsHTML(true); //指定支持html格式
			$mail->CharSet="UTF-8";
			$mail->Subject = $title;
			$mail->Body = $message;
			if($mail->Send()){
			   return true;
			}else{
			   return false;
			}
		}
		//老师的指导队伍
		public function team(){
			$id = $this->_get('uid');	//获取id
			$model=M();
			$allarr = $model->table('teaminstructors i,team t,highschool h,users u')->where('t.Captain=u.UserId and h.Id=t.SchoolId and i.TeamId=t.Id and InstructorId ='.$id )->field('i.CreateDate,t.Id,t.Name,t.Declaration,t.Fetion,u.TrueName,t.Score,h.SchoolName')->select();	//查询符合条件的团队
			//数组排序
			foreach($allarr as $key=>$val){
				$time[$key]=$val['CreateDate'];
			}
			array_multisort($time,$allarr);
			$arr = array_reverse($allarr);

			$this->assign('arr',$arr);
			$this->display();
		}
		//评委首页
		public function juryIndex(){
			$model=M();
			$high=M('highschool');						//实例化学校
			$enter=M('enterprise');						//实例化企业表
			$keyword=$this->_post('keyword');
			if(!empty($keyword)){
				$where='u.TrueName like'."'%".$keyword."%' and ";	//组合查询语句
				$this->assign('keyword',$keyword);
			}else{
				$where="";
			}
			if($_POST['numPerPage']){
				$pagesize = $this->_post('numPerPage');
				$_GET['page'] = $this->_post('pageNum');//自定义翻页类需要 GET （当前页）信息
			}else{
				$pagesize=20;
			}
			$a=$model->table('users u,teacher t,jury j')->field('distinct j.UserId,u.UserId,u.TrueName,t.Job,t.Title,t.IdCard,j.JuryCount,u.SchoolId,t.EnterpriseId')->where($where.'u.IsJury=1 and u.UserId=t.UserId and j.UserId=u.UserId')->select();
			$totalCount=count($a);
			$this->assign('totalCount',$totalCount);				//把总数发给模板
			import('@.Action.Page');
			$page = new Page($totalCount,$pagesize);				//实例化分页类
			$pageinfo = $page->getPageInfo();						//获取分页
			$this->assign('currentPage',$pageinfo['page']);			//分配当前页数
			$this->assign('pagesize',$pagesize);					//分配一页显示的条数
			$arr=$model->table('users u,teacher t,jury j')->field('distinct j.UserId,u.UserId,u.TrueName,t.Job,t.Title,t.IdCard,j.JuryCount,u.SchoolId,t.EnterpriseId')->where($where.'u.IsJury=1 and u.UserId=t.UserId and j.UserId=u.UserId')->limit($pageinfo['offset'],$pageinfo['num'])->select();	//获取评委信息
			$an=count($arr);			//获取评委数量
			//组合评委信息
			for($i=0;$i<$an;$i++){
				if(!empty($arr[$i]['SchoolId'])){
					$ar[$i]=$high->where('Id='.$arr[$i]['SchoolId'])->field('SchoolName as Name')->find();
					
				}
				if(!empty($arr[$i]['EnterpriseId'])){
					$ar[$i]=$enter->where('Id = '.$arr[$i]['EnterpriseId'])->field('Name')->find();
				}
				$ar[$i]['UserId']=$arr[$i]['UserId'];
				$ar[$i]['TrueName']=$arr[$i]['TrueName'];
				$ar[$i]['Job']=$arr[$i]['Job'];
				$ar[$i]['Title']=$arr[$i]['Title'];
				$ar[$i]['IdCard']=$arr[$i]['IdCard'];
				$ar[$i]['JuryCount']=$arr[$i]['JuryCount'];
			}
			$this->assign('arr',$ar);
			$this->display();
		} 
		//取消操作
		public function cancel(){
			$id=$this->_get('uid');					//获取用户id
			$jury=M('jury');						//实例化评委表
			$user=M('users');						//实例化用户表
			$data['IsJury']=0;						//设置取消评委
			//取消评委
			if($jury->where('UserId ='.$id)->delete() && $user->where('UserId='.$id)->save($data)){
				$this->success_ajax('修改成功');
			}else{
				$this->error_ajax('修改失败');
			}
		}
		//修改页面
		public function edit(){
			$id=$this->_get('uid');	//获得用户id
			$jury=M('jury');
			$list=$jury->field('UserId,TrueName')->where('UserId='.$id)->find();	//获取用户信息
			//获取用户详细信息 Version 1 初赛 2 复赛  3 分赛区决赛 4 总决赛 
 			$arr0=$jury->field('UserId,TrueName,JurySchools,JurySchoolNames,JuryCount')->where('Version=1 and UserId='.$id)->select();
			$arr1=$jury->field('UserId,TrueName,JurySchools,JurySchoolNames,JuryCount')->where('Version=2 and UserId='.$id)->select();
			$arr2=$jury->field('UserId,TrueName,JurySchools,JurySchoolNames,JuryCount')->where('Version=3 and UserId='.$id)->select();
			$arr3=$jury->field('UserId,TrueName,JurySchools,JurySchoolNames,JuryCount')->where('Version=4 and UserId='.$id)->select();
			$this->assign('list',$list);	//数据发给模板
			$this->assign('arr0',$arr0);	//数据发给模板
			$this->assign('arr1',$arr1);	//数据发给模板
			$this->assign('arr2',$arr2);	//数据发给模板
			$this->assign('arr3',$arr3);	//数据发给模板
			$this->display();
		}
		//学校展示页
		public function school(){
			$pro=M('province');					//实例化省份表
			$parr=$pro->field('Id,Name')->select();	//获取身份信息
			$this->assign('parr',$parr);			//数据发给模板
			$type=$this->_post('type');				//获取标志符 1 初赛 2 复赛 3 分赛区决赛 4 总决赛 
			$term=$this->_post('term');				//获取省份id
			$schools=$this->_post('schools');		//获取学校名
			$school=explode(';',$schools);			//组成数组
			array_pop($school);						//弹出最后一个空值
			if(empty($term)){						//如果没有获取id 自动为1
				$term=1;
			}
			$high=M('highschool');				//实例化高校表
			$this->assign('school',$school);	//数据发给模板
			$this->assign('ter',$term);			//数据发给模板
			$this->assign('type',$type);		//数据发给模板
			$harr=$high->field('Id,SchoolName')->where('ProvinceId='.$term)->select();		//获取高校信息
			$n=count($harr);					//获取高校数量
			//组合高校信息
			for($j=0;$j<$n;$j++){
			
				if(in_array($harr[$j]['SchoolName'],$school)){
					$harr[$j]['sta']=1;
				}else{
					$harr[$j]['sta']=0;
				}
					
			}
			$this->assign('harr',$harr);
			$this->display();	
		}
		//添加学校
		function addschool(){
			$idarr=$this->_post('schoolnames');	//获取学校id
			$type=$this->_post('type');			//获取标志符 1 初赛 2 复赛 3 分赛区决赛 4 总决赛 
			//组合标识符 Version 1 初赛 2 复赛  3 分赛区决赛 4 总决赛
			if($type==1){
				$data['Version']=1;			
			}
			if($type==2){
				$data['Version']=2;
			}
			if($type==3){
				$data['Version']=3;
			}
			if($type==4){
				$data['Version']=4;
			}
			$data['UserId']=$this->_post('uid');		//获取用户id
			$data['TrueName']=$this->_post('truename');	//获取用户名字
			$high=M('highschool');						//实例化高校表
			$jury=M('jury');							//实例化评委表
			$jury->where('UserId='.$data['UserId'].' and Version='.$type)->delete();		//删除以前的信息
			//循环插入数据库
			foreach($idarr as $id){
				$da=$high->where('Id='.$id)->field('SchoolName')->find();
				$data['JurySchoolNames']=$da['SchoolName'];
				if(!$jury->where('UserId='.$data['UserId'].' and JurySchools ='.$id)->select()){
					$data['JurySchools']=$id;
					$res=$jury->add($data);
				}
			}
			if($res){
				$this->success_ajax('添加成功');
			}else{
				$this->error_ajax('添加失败');
			}
		}
		//添加状态
		function status(){
			$jury=M('jury');
			$jury1=$this->_post('jury1');		//获取初赛值
			$jury2=$this->_post('jury2');		//获取复赛值
			$jury3=$this->_post('jury3');		//获取分赛区决赛值
			$jury4=$this->_post('jury4');		//获取总决赛值
			//初赛值不为空执行
			if(!empty($jury1)){
				$id=$this->_post('aid');				//获取学校id
				$map['JurySchools']=array('in',$id);	//组合查询语句
				$data['Section']=1;						//设置标识符 1 为初赛
				$res=$jury->where($map)->save($data);	//更新数据
			}
			//复赛值不为空执行
			if(!empty($jury2)){
				$id=$this->_post('bid');				//获取学校id
				$map['JurySchools']=array('in',$id);	//组合查询语句
				$data['Section']=2;						//设置标识符 2 为复赛
				$res=$jury->where($map)->save($data);	//更新数据
			}
			//分区赛决赛值不为空执行
			if(!empty($jury3)){
				$id=$this->_post('cid');				//获取学校id
				$map['JurySchools']=array('in',$id);	//组合查询语句
				$data['Section']=3;						//设置标识符 3 为分区赛决赛
				$res=$jury->where($map)->save($data);	//更新数据
			}
			//总决赛值不为空执行
			if(!empty($jury4)){
				$id=$this->_post('did');				//获取学校id
				$map['JurySchools']=array('in',$id);	//组合查询语句
				$data['Section']=4;						//设置标识符 4 为总决赛
				$res=$jury->where($map)->save($data);	//更新数据
			}
			if($res){
				$this->success_ajax('添加成功');
			}else{
				$this->error_ajax('添加失败');
			}
		}	
	}
